package rentals;

import java.util.*;

public class Shop {

	private ArrayList members = new ArrayList();
	private ArrayList dvds = new ArrayList();
	
	public Shop(ArrayList dvds) {
		this.dvds = dvds;
	}
	
	public void addMemeber(Member member) {
		members.add(member);
	}
	
	public void dvdRented(Member member, Dvd dvd) {
		if (members.contains(member)) {
			for (int i=0; i < dvds.size(); ++i) {
				Dvd d = (Dvd)dvds.get(i);
				if (dvd.equals(d) && d.getAvailable()) {
					member.rentDvd(dvd);
					d.setAvailable(false);
				}
			}
		}
	}
	
	public void dvdReturned(Member member, Dvd dvd) {
		if (members.contains(member)) {
			if (dvds.contains(dvd)) {
				member.returnDvd(dvd);
				dvd.setAvailable(true);
			}
		}
	}
	
	public void printAvailable() {
		System.out.println("The following Dvd's are available : ");
		for (int i=0; i < dvds.size(); ++i) {
			Dvd dvd = (Dvd)dvds.get(i);
			if (dvd.getAvailable()) {
				dvd.printDvd();
			}
		}
	}
}
